package day20171202;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class Zip {
    public static void main(String[] args) {
ZipInputStream zipInputStream=null;
ZipEntry zipEntry=null;//entry；入口
        File file=null;
        InputStream inputStream=null;
        FileOutputStream fileOutputStream=null;
        try {
            ZipFile zipFile=new ZipFile("G:\\book.zip");
            zipInputStream =new ZipInputStream(new FileInputStream("G:\\book.zip"));
            while ((zipEntry=zipInputStream.getNextEntry())!=null){
                //将压缩里面的入口文件赋给另一个对象
                //zipInputStream不是FileInputStream,不能直接读取文件

                System.out.println(zipEntry.getName());
                file=new File("G:\\book"+File.separator+zipEntry.getName());
                //File.separator是加上斜线，相当于“\\”
                file.createNewFile();


        inputStream=zipFile.getInputStream(zipEntry);//实例化
        fileOutputStream=new FileOutputStream(file);//实例化
        int a;
        while ((a=inputStream.read())!=-1){
            fileOutputStream.write(a);
        }
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}